package com.sdleyou.treepro.manager.api.company;

import com.sdleyou.treepro.common.model.utils.ResultVOUtil;
import com.sdleyou.treepro.common.model.vo.ResultVO;
import com.sdleyou.treepro.common.service.CompanyManager;
import com.sdleyou.treepro.system.version.ApiVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/api")
public class ManagerCompanyController {
    @Autowired
    private CompanyManager companyManager;

    @ApiVersion(1)
    @GetMapping("/{version}/manager/companies")
    public ResultVO companies(@RequestParam(name = "status", defaultValue = "ALL") String status,
                              @RequestParam(name = "page_num", defaultValue = "1") Integer pageNum,
                              @RequestParam(name = "page_size", defaultValue = "5") Integer pageSize) {
        return ResultVOUtil.success(companyManager.companyList(status,
                pageNum, pageSize));
    }

    /**
     * 审核公司
     *
     * @return
     */
    @ApiVersion(1)
    @PutMapping("/{version}/manager/audit/company/{company_id}")
    public ResultVO auditCompany(@PathVariable("company_id") String companyId,
                                 @RequestParam(name = "result", defaultValue = "REFUSE") @NotEmpty(message = "审核结果不能为空") String result) {
        companyManager.auditCompany(companyId, result);
        return ResultVOUtil.success();
    }
}
